/** 
 * @Description: 文件描述
 * @Author: 程前
 * @Date: 2024-11-29 16:56:50
 * @LastEditors: 程前
 * @LastEditTime: 2024-12-11 11:54:38
 */
import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import { fileURLToPath, URL } from "node:url";
import cesium from "vite-plugin-cesium";

// https://vitejs.dev/config/
export default defineConfig({
  plugins: [vue(), cesium()],
  // 静态资源基础路径 base: './' || '',
  base: process.env.NODE_ENV === 'production' ? './' : '/',
  resolve: {
    alias: {
      "@": fileURLToPath(new URL("./src", import.meta.url)),
    },
  },
  css: {
    preprocessorOptions: {
      scss: {
        additionalData: `$injectedColor: orange;`,
      },
      less: {
        javascriptEnabled: true,
      },
    },
  },
  chainWebpack: (config) => {    //这里是svg-sprite-loader插件的用法
    config.module.rules.delete('svg') //重点:删除默认配置中处理svg,
    config.module
      .rule('svg-sprite-loader')
      .test(/\.svg$/)
      .include.add(resolve('src/icons')) //处理svg目录
      .end()
      .use('svg-sprite-loader')
      .loader('svg-sprite-loader')
      .options({
        symbolId: 'icon-[name]'
      })
    config
      .plugin('html')
      .tap((args) => {
        args[0].title = 'MetrologyWorks'
        return args
      })
      .end()
    config.module
      .rule('pdf')
      .test(/\.pdf$/)
      .use('pdf')
      .loader('file-loader')
      .end()
  },
  server: {
    hmr: true,
    open: true,
    fs: {
      strict: false
    },
    // proxy: {
    //   '/assets/terrain': {
    //     changeOrigin: true,
    //     // rewrite: (path) => path.replace(/^\/terrian/, ''),
    //     // mock代理目标地址
    //     target: 'http://localhost:5174/assets/terrain/',
    //     ws: true,
    //   },
    // }

  },
  worker: {
    format: 'es'
  }
});
